package com.mysoft.gfyx.marketdevelop.controller;

import com.mysoft.framework.modeling.dto.ListDataResult;
import com.mysoft.framework.modeling.dto.LoadDataParams;
import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.gfyx.marketdevelop.controller.dto.GetProcurementRequirementMobileRequestDto;
import com.mysoft.gfyx.marketdevelop.controller.dto.GetPurchaseContactsRequestDto;
import com.mysoft.gfyx.marketdevelop.service.DeveloperContactService;
import com.mysoft.gfyx.marketdevelop.service.ProcurementRequirementService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.Map;

@PubService(value = "/procurementRequirementPub", prefix = RequestPrefix.PUB)
@Tag(name = "采购需求-PUB")
public class ProcurementRequirementPubController {
    @Resource
    private ProcurementRequirementService procurementRequirementService;

    @Resource
    private DeveloperContactService developerContactService;

    // 关联招标列表
    @PubAction(value = "/procurementRequirementList", method = RequestMethod.POST)
    public ListDataResult procurementRequirementList(@RequestBody LoadDataParams options) {
        return procurementRequirementService.loadData(options);
    }

    // 通用的获取手机号：获取商机的电话、获取开发商联系人的手机号
    @PubAction(value = "/getProcurementRequirementMobile", method = RequestMethod.POST)
    public GetProcurementRequirementMobileRequestDto getProcurementRequirementMobile(@RequestBody GetPurchaseContactsRequestDto dto) {
        if (dto.getScene().equals("developer-contact")) {//开发商联系人手机号
            Map<String, Object> developerContact = developerContactService.getContactInfo(dto.getId());
            GetProcurementRequirementMobileRequestDto developerContactDto = new GetProcurementRequirementMobileRequestDto();
            if (!developerContact.isEmpty()) {
                developerContactDto.setTel(developerContact.get("ower_mobile").toString());
            }
            return developerContactDto;
        } else {//商机联系人手机号
            return procurementRequirementService.getProcurementRequirementMobile(dto.getId());
        }

    }
}